package com.parleys.android.server.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.parleys.android.server.util.ParleysServiceUtils;
import com.parleys.server.domain.News;
import com.parleys.server.domain.types.NewsType;
import com.parleys.server.frontend.service.ParleysService;

@Controller
@RequestMapping("/news")
public class NewsController extends BaseController {

	@Autowired
	private ParleysService parleysService;

	@RequestMapping(method = RequestMethod.GET)
	public List<News> getNews() {
		return this.parleysService.getNews(NewsType.GENERAL, 0, 0, Integer.MAX_VALUE).getOverviews();
	}

	@RequestMapping(value = "/start/{from}", method = RequestMethod.GET)
	public List<News> getNewsFrom(@PathVariable("from") final long from) {
		List<News> result = this.getNews();
		ParleysServiceUtils.filterEntity(result, from);
		return result;
	}

}
